/* GUI CONVERTED from sosorp03.p (converter v1.76) Mon Jul 22 13:43:41 2002 */
/* sosorp03.p - SALES BOOKING REPORT BY ITEM                            */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                  */
/* All rights reserved worldwide.  This is an unpublished work.         */
/* $Revision: 1.9.1.8 $                                                 */
/*F0PN*/ /*K0L2*/
/*V8:ConvertMode=FullGUIReport                                       */
/* REVISION: 1.0      LAST MODIFIED: 07/24/86   BY: PML              */
/* REVISION: 1.0      LAST MODIFIED: 08/29/86   BY: EMB *12*         */
/* REVISION: 2.0      LAST MODIFIED: 02/15/88   BY: pml*A46* */
/* REVISION: 4.0      LAST MODIFIED: 02/12/88   BY: FLM *A175**/
/* REVISION: 4.0      LAST MODIFIED: 02/08/89   BY: JLC *C0028*/
/* REVISION: 5.0      LAST MODIFIED: 07/05/89   BY: BJJ *B106* */
/* REVISION: 5.0      LAST MODIFIED: 11/14/89   BY: MLB *B388**/
/* REVISION: 6.0      LAST MODIFIED: 04/05/90   BY: pml *D001**/
/* REVISION: 6.0      LAST MODIFIED: 04/11/90   BY: ftb *D002* added site*/
/* REVISION: 6.0      LAST MODIFIED: 04/20/90   BY: ftb **/
/* REVISION: 6.0      LAST MODIFIED: 07/13/91   BY: afs *D769**/
/* REVISION: 6.0      LAST MODIFIED: 10/21/91   BY: afs *D903**/
/* REVISION: 7.0      LAST MODIFIED: 04/10/92   BY: dld *F358**/
/* REVISION: 7.0      LAST MODIFIED: 07/16/92   BY: afs *F774**/
/* REVISION: 7.3      LAST MODIFIED: 10/21/92   BY: afs *G221**/
/* REVISION: 7.3      LAST MODIFIED: 04/10/96   BY: jzw *G1P6**/
/* REVISION: 8.6      LAST MODIFIED: 10/02/97   BY: ckm *K0L2**/
/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane    */
/* REVISION: 8.6E     LAST MODIFIED: 04/21/98   BY: *J2JY* Niranjan R.  */
/* REVISION: 8.6E     LAST MODIFIED: 07/04/98   BY: *L024* Sami Kureishy*/
/* REVISION: 8.6E     LAST MODIFIED: 07/19/99   BY: *J3HW* Hemali Desai */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00   BY: *N08T* Annasaheb Rahane */
/* REVISION: 9.1      LAST MODIFIED: 08/14/00   BY: *N0K6* Mudit Mehta      */
/* Revision: 1.9.1.4.1.6      BY: Ellen Borden   DATE: 10/15/01   ECO: *P004* */
/* Revision: 1.9.1.7      BY: Hareesh V.      DATE: 06/21/02   ECO: *N1HY* */
/* $Revision: 1.9.1.8 $     BY: Annasaheb Rahane   DATE: 07/18/02   ECO: *P0BB* */
/*                                                                          */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

/*GUI global preprocessor directive settings */
&GLOBAL-DEFINE PP_PGM_RP TRUE
&GLOBAL-DEFINE PP_ENV_GUI TRUE


/*GUI preprocessor directive settings */
&SCOPED-DEFINE PP_GUI_CONVERT_MODE REPORT

{mfdtitle.i "2+ "}

/* ********** Begin Translatable Strings Definitions ********* */

&SCOPED-DEFINE sosorp03_p_1 "Ext Price"
/* MaxLen: Comment: */

&SCOPED-DEFINE sosorp03_p_4 "Ext Margin"
/* MaxLen: Comment: */

/* REPLACED Userid: WITH User ID:       */

&SCOPED-DEFINE sosorp03_p_9 "Show Revision Detail"
/* MaxLen: Comment: */

&SCOPED-DEFINE sosorp03_p_10 "Qty Ordered"
/* MaxLen: Comment: */

&SCOPED-DEFINE sosorp03_p_13 "Unit Price"
/* MaxLen: Comment: */

&SCOPED-DEFINE sosorp03_p_14 "Summary/Detail"
/* MaxLen: Comment: */

/* ********** End Translatable Strings Definitions ********* */

define variable addr like tr_addr.
define variable addr1 like tr_addr.
define variable so_job like tr_so_job.
define variable so_job1 like tr_so_job.
define variable part like tr_part.
define variable part1 like tr_part.
define variable trdate like tr_effdate.
define variable trdate1 like tr_effdate.
define variable region like cm_region.
define variable region1 like cm_region.
define variable site like so_site.
define variable site1 like so_site.
define variable name like ad_name.
define variable ext_price like tr_price label {&sosorp03_p_1}
   format "->,>>>,>>>,>>9.99".
define variable gr_margin like tr_price.
define variable ext_gr_margin like tr_price label {&sosorp03_p_4}
   format "->,>>>,>>>,>>9.99<<<".
define variable summary like mfc_logical format {&sosorp03_p_14}
   label {&sosorp03_p_14}.
define variable base_rpt like so_curr.

define variable base_price like tr_price.
define variable disp_curr as character format "x(1)" label "C".
define variable prod_line like tr_prod_line.
define variable prod_line1 like tr_prod_line.
define variable desc2 like pl_desc.
define variable show_rev like mfc_logical initial false
   label {&sosorp03_p_9}.
define variable mc-error-number like msg_nbr no-undo.
define variable print_cmmts like mfc_logical initial no no-undo label "Include Reason/Comments".
define variable tr-cmtindx  like cmt_indx no-undo.
define variable i as integer no-undo.
define variable c-reason as character format "x(15)" no-undo.

assign
   c-reason = getTermLabelRtColon("REASON",15).

{gprunpdf.i "mcpl" "p"}


/*GUI preprocessor Frame A define */
&SCOPED-DEFINE PP_FRAME_NAME A

FORM /*GUI*/ 
   
 RECT-FRAME       AT ROW 1.4 COLUMN 1.25
 RECT-FRAME-LABEL AT ROW 1   COLUMN 3 NO-LABEL
 SKIP(.1)  /*GUI*/
part           colon 15
   part1          label {t001.i} colon 49 skip
   prod_line      colon 15
   prod_line1     label {t001.i} colon 49 skip
   trdate         colon 15
   trdate1        label {t001.i} colon 49 skip
   addr           colon 15
   addr1          label {t001.i} colon 49 skip
   so_job         colon 15
   so_job1        label {t001.i} colon 49 skip
   region         colon 15
   region1        label {t001.i} colon 49
   site           colon /* 18 */ 15
   site1          label {t001.i} colon 49 skip(1)

   show_rev       colon 30
   summary        colon 30 skip
   base_rpt       colon 30 skip
   print_cmmts    colon 30 skip
 SKIP(.4)  /*GUI*/
with frame a side-labels
   width 80 NO-BOX THREE-D /*GUI*/.

 DEFINE VARIABLE F-a-title AS CHARACTER.
 F-a-title = &IF (DEFINED(SELECTION_CRITERIA) = 0)
  &THEN " Selection Criteria "
  &ELSE {&SELECTION_CRITERIA}
  &ENDIF .
 RECT-FRAME-LABEL:SCREEN-VALUE in frame a = F-a-title.
 RECT-FRAME-LABEL:WIDTH-PIXELS in frame a =
  FONT-TABLE:GET-TEXT-WIDTH-PIXELS(
  RECT-FRAME-LABEL:SCREEN-VALUE in frame a + " ", RECT-FRAME-LABEL:FONT).
 RECT-FRAME:HEIGHT-PIXELS in frame a =
  FRAME a:HEIGHT-PIXELS - RECT-FRAME:Y in frame a - 2.
 RECT-FRAME:WIDTH-CHARS IN FRAME a = FRAME a:WIDTH-CHARS - .5. /*GUI*/

/*GUI preprocessor Frame A undefine */
&UNDEFINE PP_FRAME_NAME



/* SET EXTERNAL LABELS */
setFrameLabels(frame a:handle).
{wbrp01.i}


/*GUI*/ {mfguirpa.i true "printer" 132 " " " " " "  }

/*GUI repeat : */
/*GUI*/ procedure p-enable-ui:

   if part1 = hi_char then part1 = "".
   if addr1 = hi_char then addr1 = "".
   if so_job1 = hi_char then so_job1 = "".
   if site1 = hi_char then site1 = "".
   if trdate = low_date then trdate = ?.
   if trdate1 = hi_date then trdate1 = ?.
   if prod_line1 = hi_char then prod_line1 = "".
   if region1 = hi_char then region1 = "".

   
run p-action-fields (input "display").
run p-action-fields (input "enable").
end procedure. /* p-enable-ui, replacement of Data-Entry GUI*/

/*GUI*/ procedure p-report-quote:


   {wbrp06.i &command = update
             &fields = "  part part1 prod_line prod_line1 trdate trdate1
                          addr addr1 so_job so_job1 region region1
                          site site1  show_rev summary base_rpt"
             &frm = "a"}

   if (c-application-mode <> 'web') or
      (c-application-mode = 'web' and
      (c-web-request begins 'data')) then do:

      bcdparm = "".
      {mfquoter.i part       }
      {mfquoter.i part1      }
      {mfquoter.i prod_line  }
      {mfquoter.i prod_line1 }
      {mfquoter.i trdate     }
      {mfquoter.i trdate1    }
      {mfquoter.i addr       }
      {mfquoter.i addr1      }
      {mfquoter.i so_job     }
      {mfquoter.i so_job1    }
      {mfquoter.i region     }
      {mfquoter.i region1    }
      {mfquoter.i site }
      {mfquoter.i site1}
      {mfquoter.i show_rev   }
      {mfquoter.i summary    }
      {mfquoter.i base_rpt   }
      {mfquoter.i print_cmmts }

      if part1 = "" then part1 = hi_char.
      if prod_line1 = "" then prod_line1 = hi_char.
      if addr1 = "" then addr1 = hi_char.
      if trdate = ? then trdate = low_date.
      if trdate1 = ? then trdate1 = hi_date.
      if so_job1 = "" then so_job1 = hi_char.
      if region1 = "" then region1 = hi_char.
      if site1 = "" then site1 = hi_char.

   end.

   /* OUTPUT DESTINATION SELECTION */
   
/*GUI*/ end procedure. /* p-report-quote */
/*GUI - Field Trigger Section */

/*GUI MFSELxxx removed*/
/*GUI*/ procedure p-report:
/*GUI*/   {gpprtrpa.i "printer" 132 " " " " " " " " }
/*GUI*/   mainloop: do on error undo, return error on endkey undo, return error:


    {hksimsg.i site site1}      /*fdn*/


   {mfphead.i}

   for each tr_hist where (tr_part >= part and tr_part <= part1)
         and (tr_prod_line >= prod_line and tr_prod_line <= prod_line1)
         and (tr_effdate >= trdate and tr_effdate <= trdate1)
         and (tr_addr >= addr and tr_addr <= addr1)
         and (tr_so_job >= so_job and tr_so_job <= so_job1)
         and (tr_site >= site and tr_site <= site1)
        AND LOOKUP(tr_site,GLOBAL_user_site) > 0
         and tr_type = "ORD-SO"

         and ((base_rpt = "")
         or (tr_curr = base_rpt))
         use-index tr_eff_trnbr no-lock,
         each cm_mstr where cm_addr = tr_addr and
             (cm_region >= region and cm_region <= region1) no-lock
         break by tr_prod_line by tr_part by tr_effdate with frame b width 132:

      /* SET EXTERNAL LABELS */
      setFrameLabels(frame b:handle).

      if first-of(tr_prod_line) then do:
         find pl_mstr where pl_prod_line = tr_prod_line no-lock no-error.
         if available pl_mstr then do:
            desc2 = pl_desc.
            if page-size - line-counter < 3 then page.
            if not summary then display with frame b STREAM-IO /*GUI*/ .
            else display with frame c STREAM-IO /*GUI*/ .

            put {gplblfmt.i
               &FUNC=getTermLabel(""PRODUCT_LINE"",14)
               &CONCAT="': '"
               } pl_prod_line
               " " pl_desc.
         end.
      end.

      base_price = tr_price.
      disp_curr = "".

      if base_rpt <> "" and tr_curr <> base_curr then
   do:

         {gprunp.i "mcpl" "p" "mc-curr-conv"
            "(input base_curr,
              input tr_curr,
              input tr_ex_rate2,
              input tr_ex_rate,
              input base_price,
              input false,
              output base_price,
              output mc-error-number)"}.
         if mc-error-number <> 0 then do:
            {pxmsg.i &MSGNUM=mc-error-number &ERRORLEVEL=2}
         end.
      end. /*IF BASE_RPT <> "" ... */

      if base_rpt = ""
         and tr_curr <> base_curr then
         disp_curr = getTermLabel("YES",1).
      ext_price = tr_qty_req * base_price.
      gr_margin = tr_price - tr_mtl_std - tr_lbr_std
                  - tr_bdn_std - tr_ovh_std - tr_sub_std.

      if base_rpt <> ""
         and tr_curr <> base_curr then
   do:

         {gprunp.i "mcpl" "p" "mc-curr-conv"
            "(input base_curr,
              input tr_curr,
              input tr_ex_rate2,
              input tr_ex_rate,
              input gr_margin,
              input false,
              output gr_margin,
              output mc-error-number)"}.
         if mc-error-number <> 0 then do:
            {pxmsg.i &MSGNUM=mc-error-number &ERRORLEVEL=2}
         end.
      end. /*IF BASE_RPT <> "" ... */

      ext_gr_margin = tr_qty_req * gr_margin.

      accumulate ext_gr_margin (total by tr_prod_line by tr_part).
      accumulate tr_qty_req (total by tr_prod_line by tr_part).
      accumulate ext_price (total by tr_prod_line by tr_part).

      find pt_mstr where pt_part = tr_part no-lock no-wait no-error.

      if not summary then do:
         name = "".
         find ad_mstr where ad_addr = tr_addr no-lock no-wait no-error.
         if available ad_mstr then name = ad_name.

         if first-of(tr_part)  then do:
            if page-size - line-counter < 4 then page.
            display WITH STREAM-IO /*GUI*/ .

            put {gplblfmt.i
               &FUNC=getTermLabel(""ITEM"",4)
               &CONCAT="': '"
               } tr_part " ".
            if available pt_mstr then put pt_desc1 " " pt_desc2.

            put "  " {gplblfmt.i
               &FUNC=getTermLabel(""UNIT_OF_MEASURE"",4)
               &CONCAT="': '"
               } tr_um
               skip.
         end.

         if page-size - line-counter < 3 then page.
         display tr_trnbr tr_ship_type
            tr_effdate tr_so_job tr_addr
            name format "X(24)" tr_qty_req label {&sosorp03_p_10}
            disp_curr base_price label {&sosorp03_p_13} ext_price
            ext_gr_margin WITH STREAM-IO /*GUI*/ .

         if show_rev then
         put space(9)

            {gplblfmt.i
            &FUNC=getTermLabel(""REVISION"",8)
            &CONCAT="': '"
            } tr_ord_rev " "
            {gplblfmt.i
            &FUNC=getTermLabel(""USER_ID"",7)
            &CONCAT="': '"
            } tr_userid
            skip.

         if (tr_fldchg_cmtindx <> 0 or tr_rsn_code > " ") and
            print_cmmts then do:
            display WITH STREAM-IO /*GUI*/ .
            put space(4) c-reason tr_rsn_code skip.
            {gpcmtprt.i
               &type=RP
               &id= tr_fldchg_cmtindx
               &pos=5
               &command="down 1."}
            down 1 with frame b.
         end.    /* IF TR_FLDCHG_CMTINDX <>0 */

         if last-of(tr_part)  then do:
            if page-size - line-counter < 2 then page.
            underline tr_qty_req ext_price ext_gr_margin with frame b.

            display getTermLabel("ITEM_TOTAL",27) + ":" @ name
               accum total by tr_part (tr_qty_req) @ tr_qty_req
               accum total by tr_part (ext_price) @ ext_price
               accum total by tr_part (ext_gr_margin) @ ext_gr_margin with
               frame b STREAM-IO /*GUI*/ .
         end.
         if last-of(tr_prod_line)  then do:
            if page-size - line-counter < 2 then page.
            underline tr_qty_req ext_price ext_gr_margin.

            display getTermLabel("PRODUCT_LINE_TOTAL",27) + ":" @ name
               accum total by tr_prod_line (tr_qty_req) @ tr_qty_req
               accum total by tr_prod_line (ext_price) @ ext_price
               accum total by tr_prod_line (ext_gr_margin) @ ext_gr_margin WITH STREAM-IO /*GUI*/ .
         end.

         if last(tr_prod_line)  then do:
            if page-size - line-counter < 2 then page.
            underline  tr_qty_req ext_price ext_gr_margin.

            display  getTermLabel("REPORT_TOTAL",27) + ":" @ name
               accum total  (tr_qty_req) @ tr_qty_req
               accum total  (ext_price) @ ext_price
               accum total  (ext_gr_margin) @ ext_gr_margin WITH STREAM-IO /*GUI*/ .
         end.
      end.  /* not summary */

      if summary then do:
         /* SET EXTERNAL LABELS */
         setFrameLabels(frame c:handle).
         if last-of(tr_part) then do:
            if page-size - line-counter < 2 then page.
            display tr_part with frame c down width 132 STREAM-IO /*GUI*/ .
            if available pt_mstr then display pt_um pt_desc1  with frame c STREAM-IO /*GUI*/ .
            display
               accum total by tr_part (tr_qty_req) @ tr_qty_req
               accum total by tr_part (ext_price) @ ext_price
               accum total by tr_part (ext_gr_margin) @ ext_gr_margin
            with frame c down width 132 STREAM-IO /*GUI*/ .
            if available pt_mstr and pt_desc2 <> "" then do:
               down 1 with frame c.
               display pt_desc2 @ pt_desc1 with frame c STREAM-IO /*GUI*/ .
            end.
         end.
         if last-of(tr_prod_line)  then do:
            if page-size - line-counter < 2 then page.
            underline tr_qty_req ext_price ext_gr_margin with frame c.

            display  getTermLabel("PRODUCT_LINE_TOTAL",23) + ":" @ pt_desc1
               accum total by tr_prod_line (tr_qty_req) @ tr_qty_req
               accum total by tr_prod_line (ext_price) @ ext_price
               accum total by tr_prod_line (ext_gr_margin) @ ext_gr_margin
            with frame c STREAM-IO /*GUI*/ .
         end.

         if last(tr_prod_line)  then do:
            if page-size - line-counter < 2 then page.
            underline tr_qty_req ext_price ext_gr_margin with frame c.

            display  getTermLabel("REPORT_TOTAL",23) + ":" @ pt_desc1
               accum total  (tr_qty_req) @ tr_qty_req
               accum total  (ext_price) @ ext_price
               accum total  (ext_gr_margin) @ ext_gr_margin with frame c STREAM-IO /*GUI*/ .
         end.
      end. /* summary*/
      
/*GUI*/ {mfguichk.i } /*Replace mfrpchk*/

   end. /*for each*/
   /* REPORT TRAILER  */
   
/*GUI*/ {mfguitrl.i} /*Replace mfrtrail*/

/*GUI*/ {mfgrptrm.i} /*Report-to-Window*/

end.

{wbrp04.i &frame-spec = a}

/*GUI*/ end procedure. /*p-report*/
/*GUI*/ {mfguirpb.i &flds=" part part1 prod_line prod_line1 trdate trdate1 addr addr1 so_job so_job1 region region1 site site1 show_rev summary base_rpt print_cmmts "} /*Drive the Report*/
